public class MST0109 {
    /**
     * 面试题 01.09. 字符串轮转
     * 字符串轮转。给定两个字符串s1和s2，请编写代码检查s2是否为s1旋转而成（比如，waterbottle是erbottlewat旋转后的字符串）。
     * 示例1:
     *  输入：s1 = "waterbottle", s2 = "erbottlewat"
     *  输出：True
     * 示例2:
     *  输入：s1 = "aa", s2 = "aba"
     *  输出：False
     */

    public boolean isFlipedString(String s1, String s2) {
        //两种方法，一种方法是找到旋转点，旋转字符串，将其拼接比较字符串是否相等
          if(s1==null&&s2==null){
            return true;
        }
           if(s1==null||s2==null){
            return false;
        }
           if (s1.length()!=s2.length()){
            return false;
        }
           if (s1.equals(s2)){
               return true;
           }


            int index=0;
            while (s2.indexOf(s1.substring(0,index+1))!=-1){
                index++;
            }
            StringBuilder stringBuilder=new StringBuilder();
            stringBuilder.append( s1.substring(index,s1.length()));
            stringBuilder.append(s1.substring(0,index));

            return stringBuilder.toString().equals(s2);
    }

    public boolean isFlipedString2(String s1, String s2) {
        //两种方法，一种方法是找到旋转点，旋转字符串，将其拼接比较字符串是否相等
        if(s1==null&&s2==null){
            return true;
        }
        if(s1==null||s2==null){
            return false;
        }
        if (s1.length()!=s2.length()){
            return false;
        }
        if (s1.equals(s2)){
            return true;
        }



        StringBuilder stringBuilder=new StringBuilder();

        stringBuilder.append(s2);
        stringBuilder.append(s2);
        if (stringBuilder.toString().contains(s1)){
            return true;
        }else {
            return false;
        }
    }
}
